package com.jidu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jidu.common.utils.poi.ExcelUtil;
import com.jidu.domain.SysClass;
import com.jidu.service.ISysClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jidu.common.annotation.Log;
import com.jidu.common.core.controller.BaseController;
import com.jidu.common.core.domain.AjaxResult;
import com.jidu.common.enums.BusinessType;
import com.jidu.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author ruoyi
 * @date 2024-07-19
 */
@Slf4j
@Api(tags = "班级 controller")
@RestController
@RequestMapping("/system/class")
public class SysClassController extends BaseController
{
    @Autowired
    private ISysClassService sysClassService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysClass sysClass)
    {
        startPage();
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:class:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClass sysClass)
    {
        List<SysClass> list = sysClassService.selectSysClassList(sysClass);
        ExcelUtil<SysClass> util = new ExcelUtil<SysClass>(SysClass.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @ApiOperation(value = "获取班级详细信息")
    @PreAuthorize("@ss.hasPermi('system:class:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysClassService.selectSysClassById(id));
    }

    /**
     * 新增班级
     */
    @ApiOperation(value = "新增班级")
    @PreAuthorize("@ss.hasPermi('system:class:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysClass sysClass)
    {
        return toAjax(sysClassService.insertSysClass(sysClass));
    }

    /**
     * 修改班级：只修改名称
     */
    @ApiOperation(value = "编辑班级")
    @PreAuthorize("@ss.hasPermi('system:class:edit')")
    @Log(title = "修改班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysClass sysClass)
    {
        return toAjax(sysClassService.updateSysClass(sysClass));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('system:class:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @ApiOperation(value = "逻辑删除班级")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysClassService.updateSysClassByIds(ids));
    }

    /**
     * 班级列表
     */
    @ApiOperation(value = "班级列表")
    @GetMapping("/class/list")
    public TableDataInfo classList(@RequestParam(value = "className",required = false)String className,
                                   @RequestParam(value = "teacherId",required = false)Long teacherId){
        startPage();
        return getDataTable(sysClassService.classList(className,teacherId));
    }

    /**
     * 班级管理列表
     */
    @ApiOperation(value = "班级管理列表")
    @GetMapping("/class/two/list")
    public TableDataInfo classTwoList(@RequestParam(value = "classId")Long classId){
        startPage();
        return getDataTable(sysClassService.classTwoList(classId));
    }

    /**
     * 配置班级上课时间
     */

}
